#pragma once

#include "Funds.h"
#include "CustomerPosition.h"

class Customer : boost::noncopyable
{
public:
	Customer(char const* id, char const* shanghaiClientID,char const* password)
		:m_id(id),m_shanghaiClientID(shanghaiClientID),m_password(password),
		m_isSetOrginalAmount(false)
	{
	}

	~Customer(void){}

	char const* GetID() const {return m_id.c_str();}
	char const* GetShanghaiClientID() const {return m_shanghaiClientID.c_str();}
	char const* GetPassword() const {return m_password.c_str();}

	PositionValue const& GetPosition(PositionKey const& key) const { return m_position.Get(key); }

	PositionValue const& GetPosition(Dealing const& dealing) const { return m_position.Get(dealing);}

	double GetAvailable() const;

	void SetOrginalAmount(double available);

	bool IsSetOrginalAmount() const { return m_isSetOrginalAmount; }

	void UpdatePosition(Trade const& trade)
	{
		m_position.OnTrade(trade);
	}

	bool Freeze(int serialNumber, double amount)
	{
		return m_funds.Freeze(serialNumber,amount);
	}

	bool TryFreeze(double amount)
	{
		return m_funds.HasEnough(amount);
	}
	void Unfreeze(int serialNumber)
	{
		m_funds.Unfreeze(serialNumber);
	}

	Funds& GetFunds()
	{
		return m_funds;
	}

private:
	Customer(Customer const& other);

	std::string m_id;
	std::string m_shanghaiClientID;
	std::string m_password;

	Funds m_funds;
	CustomerPosition m_position;
	bool m_isSetOrginalAmount;
};
